import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: resolve => require(['@/views/Login.vue'], resolve),
  },
  {
    path: '/HomePage',
    name: 'HomePage',
    component: resolve => require(['@/views/HomePage.vue'], resolve),
    children: [
      {
        path: '/HomePage/Content',
        name: 'Content',
        component: resolve => require(['@/views/Content.vue'], resolve),
        children:[
          {
            path: '/HomePageView',
            name: 'HomePageView',
            component: resolve => require(['../components/ContentView/HomePageView.vue'], resolve),
          },
          {
            path: '/UserPageView',
            name: 'UserPageView',
            component: resolve => require(['../components/ContentView/UserPageView.vue'], resolve),
          },
          {
            path: '/PrivilegeManagement',
            name: 'PrivilegeManagement',
            component: resolve => require(['../components/ContentView/PrivilegeManagement.vue'], resolve),
          },
          {
            path: '/FunctionPageView',
            name: 'FunctionPageView',
            component: resolve => require(['../components/ContentView/FunctionPageView.vue'], resolve),
          },
        ]
      }
    ]
  },
  {
    path: '/CAD',
    name: 'CAD',
    component: resolve => require(['@/views/CadView.vue'], resolve),
  },
  {
    path: '/PicView',
    name: 'PicView',
    component: resolve => require(['@/views/PicView.vue'], resolve),
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
